package noobteam.deartrainer.controller;

import noobteam.deartrainer.service.ChatService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author admin
 */
@RestController
public class ChatController {

    @Resource
    private ChatService chatService;

    @RequestMapping("/createChat")
    public String createChat(@RequestParam Map<String, String> chat) {
        boolean isSucceed = chatService.createChat(chat);
        if (isSucceed) {
            return "发送成功！";
        }
        return "发送失败";
    }

    @RequestMapping("/deleteChat")
    public String deleteChat(@RequestParam Integer chatId) {
        boolean isSucceed = chatService.deleteChat(chatId);
        if (isSucceed) {
            return "撤回成功！";
        }
        return "撤回失败";
    }

    @RequestMapping("/getChatHistory")
    public List<Map<String, String>> getChatHistory(@RequestParam Map<String, String> map) {
        return chatService.getChatHistory(map);
    }

    @RequestMapping("/getChatAllHistoryOfUser")
    public List<Map<String, Object>> getChatAllHistoryOfUser(@RequestParam Map<String, Object> user) {
        return chatService.getChatAllHistoryOfUser(user);
    }
}
